'\" t
.\"     Title: modbus_mapping_new
.\"    Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\"      Date: 10/06/2013
.\"    Manual: Libmodbus Manual
.\"    Source: libmodbus 3.0.4
.\"  Language: English
.\"
.TH "MODBUS_MAPPING_NEW" "3" "10/06/2013" "libmodbus 3\&.0\&.4" "Libmodbus Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
modbus_mapping_new \- allocate four arrays of bits and registers
.SH "SYNOPSIS"
.sp
\fBmodbus_mapping_t\fR modbus_mapping_new(int \fInb_bits\fR, int \fInb_input_bits\fR, int \fInb_registers\fR, int \fInb_input_registers\fR);*
.SH "DESCRIPTION"
.sp
The \fImodbus_mapping_new()\fR function shall allocate four arrays to store bits, input bits, registers and inputs registers\&. The pointers are stored in modbus_mapping_t structure\&. All values of the arrays are initialized to zero\&.
.sp
If it isn\(cqt necessary to allocate an array for a specific type of data, you can pass the zero value in argument, the associated pointer will be NULL\&.
.sp
This function is convenient to handle requests in a Modbus server/slave\&.
.SH "RETURN VALUE"
.sp
The \fImodbus_mapping_new()\fR function shall return the new allocated structure if successful\&. Otherwise it shall return NULL and set errno\&.
.SH "ERRORS"
.PP
ENOMEM
.RS 4
Not enough memory
.RE
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
/* The fist value of each array is accessible from the 0 address\&. */
mb_mapping = modbus_mapping_new(BITS_ADDRESS + BITS_NB,
                                INPUT_BITS_ADDRESS + INPUT_BITS_NB,
                                REGISTERS_ADDRESS + REGISTERS_NB,
                                INPUT_REGISTERS_ADDRESS + INPUT_REGISTERS_NB);
if (mb_mapping == NULL) {
    fprintf(stderr, "Failed to allocate the mapping: %s\en",
            modbus_strerror(errno));
    modbus_free(ctx);
    return \-1;
}
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBmodbus_mapping_free\fR(3)
.SH "AUTHORS"
.sp
The libmodbus documentation was written by St\('ephane Raimbault <\m[blue]\fBstephane\&.raimbault@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2>
.SH "NOTES"
.IP " 1." 4
stephane.raimbault@gmail.com
.RS 4
\%mailto:stephane.raimbault@gmail.com
.RE
